package nz.ac.massey.cs.compile;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import org.java.plugin.Plugin;

import nz.ac.massey.cs.domain.IConstraint;
import nz.ac.massey.cs.domain.ISudoku;
import nz.ac.massey.cs.presentaion.IDrawer;

public class sudoku9x9Drawer extends Plugin implements IDrawer{

	@Override
	public JPanel buildSudokuBoard(ISudoku sudoku, JPanel sudokuBoard, JButton[][] buttons) {
		sudokuBoard.removeAll();
		sudokuBoard.setLayout(new GridLayout(sudoku.getColSize()+1,sudoku.getRowSize()+1,1,1));
		sudokuBoard.setBackground(Color.cyan);
		
		for(int y = 0; y < sudoku.getColSize(); y++)
		{
			for(int x = 0; x < sudoku.getRowSize();x++)
			{
				JButton button = new JButton(sudoku.getCellByIndex(y, x).getValue());
				sudokuBoard.add(button);
				buttons[y][x] = button;
				Color blockColor = new Color(64224208);
				
				if(x < 3)
				{
					if(y < 3)
					{
						button.setBackground(blockColor);
					}
					else if(y < 6)
					{
						button.setBackground(Color.orange);
					} 
					else
					{
						button.setBackground(blockColor);
					}
				}
				else if(x < 6)
				{
					if(y < 3)
					{
						button.setBackground(Color.orange);
					}
					else if(y < 6)
					{
						button.setBackground(blockColor);
					} 
					else
					{
						button.setBackground(Color.orange);
					}
				}
				else 
				{
					if(y < 3)
					{
						button.setBackground(blockColor);
					}
					else if(y < 6)
					{
						button.setBackground(Color.orange);
					} 
					else
					{
						button.setBackground(blockColor);
					}
				}
			}
		}
		return sudokuBoard;
	}

	@Override
	protected void doStart() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void doStop() throws Exception {
		// TODO Auto-generated method stub
		
	}

}
